package com.supercube.sport.yoga.exception;

import com.supercube.sport.yoga.utils.ResultInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Description：
 * Created with IntelliJ IDEA
 * Created By guowen
 * Date: 2020/3/17
 * Time: 21:23
 */
@RestControllerAdvice
public class BusinessException {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @ExceptionHandler(MethodArgumentNotValidException.class)
    public ResultInfo notValidExceptionHandler(MethodArgumentNotValidException e){
        logger.error(e.getMessage());
        return ResultInfo.failed(e.getBindingResult().getFieldError().getDefaultMessage());
    }

    @ExceptionHandler(Exception.class)
    public ResultInfo handleExcetpion(Exception e){
        logger.error(e.getMessage());
        return ResultInfo.failed();
    }
}